package info.openlvb.openface.client.base.machine;

import info.openlvb.openface.client.handler.DeleteMachineListener;
import info.openlvb.openface.client.handler.ModifyMachineListener;

import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.data.Record;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;

public class MachineWindow extends DialogBox{

	//private Record record;
	private TextBox txt_nom, txt_desc;
	//private ListMachinePanel listMachinePanel;
	//private final LdapServiceAsync ldapService = GWT.create(LdapService.class);
	
	public MachineWindow(Record record, ListMachinePanel listMachinePanel) {
		super();
		//this.record = record;
		setTitle("Gestion d'un ordinateur");
		setAnimationEnabled(true);
		setGlassEnabled(true);
		VerticalPanel content = new VerticalPanel();
		HTML lbl_title = new HTML("<h3>Modification d'un ordinateur</h3></br>");
		content.add(lbl_title);

		FlexTable descTable = new FlexTable();
		descTable.setCellSpacing(20);
		Label lbl_nom = new Label("Nom de l'ordinateur");
		descTable.setWidget(0, 0, lbl_nom);
		txt_nom = new TextBox();
		txt_nom.setText(record.getAsString("nom"));
		descTable.setWidget(0, 1, txt_nom);

		Label lbl_desc = new Label("Description de l'ordinateur");
		descTable.setWidget(1, 0, lbl_desc);
		txt_desc = new TextBox();
		txt_desc.setText(record.getAsString("description"));
		descTable.setWidget(1, 1, txt_desc);

		content.add(descTable);
		
		Button closeBtn = new Button("Close");
		closeBtn.addListener(new ButtonListenerAdapter(){
			public void onClick(Button button, EventObject e) {
				MachineWindow.this.hide();
			}			
		});
		Button modifyBtn = new Button("Modify");
		modifyBtn.addListener(new ModifyMachineListener(this,listMachinePanel,record.getAsString("nom")));
		Button deleteBtn = new Button("Delete");
		deleteBtn.addListener(new DeleteMachineListener(this,listMachinePanel,record.getAsString("nom")));
		Panel btPanel = new Panel();
		btPanel.addButton(modifyBtn);
		btPanel.addButton(deleteBtn);
		btPanel.addButton(closeBtn);
		content.add(btPanel);
		add(content);
		show();
	}

	public TextBox getTxt_nom() {
		return txt_nom;
	}

	public TextBox getTxt_desc() {
		return txt_desc;
	}

}
